package com.woori.web;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jasypt.util.password.BasicPasswordEncryptor;

public class TestPasswordServlet extends HttpServlet {

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        response.setContentType("text/html;charset=euc-kr");
        
        String userPassword = "asdf";
        String inputPassword = request.getParameter("password");
        BasicPasswordEncryptor passwordEncryptor = new BasicPasswordEncryptor();
        String encryptedPassword = passwordEncryptor.encryptPassword(userPassword);
        System.out.println(encryptedPassword);
        if (passwordEncryptor.checkPassword(inputPassword, encryptedPassword)) {
            out.println("password OK."+encryptedPassword);
        } else {
            out.println("password Error.");
        }
        out.flush();
        out.close();
    }
}